-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slim down Element
, various dtype-related improvements and changes
#256
Conversation
One thing we've discussed in #254 and I'd like to point out here again:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks nice, though I haven't checked the error types yet
I guess this would be best resolved by dropping |
That's a separate question, although a good point. I'll take a look if we can drop it now. What about type aliases? c32 <--> complex64
c64 <--> complex128 |
I think we should leave them, they are consistent with the nomenclature of the |
Maybe, at the very least then, it's worth mentioning it in the docstrings of type aliases? (that c32 is |
6073114
to
da7685d
Compare
Actually, I have considered this further, we should drop them outright and just use The doc comment would make sense though, but I would then attach it to the trait impl for these two types (as the type aliases are no more). |
dff5812
to
072cd43
Compare
I'm also OK to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @aldanor and @adamreichold, I like the way this PR simplified things
Already done ( |
@adamreichold @kngwyu I'm almost done with dropping One (cosmetic) question though – do we want a top-level This came up from fixing multiple doctests that used to look like this: assert_eq!(dtype.get_datatype().unwrap(), numpy::DataType::Int32); The current version is assert_eq!(dtype.is_equiv_to(numpy::PyArrayDescr::of::<i32>(py))); My suggestion is to also add a top-level alias, like assert_eq!(dtype.is_equiv_to(numpy::dtype::<i32>(py)));
// or
assert_eq!(dtype.is_equiv_to(numpy::dtype_of::<i32>(py))); |
Sounds reasonable. I would go for |
(You can check the extensions by running |
aa6ec7a
to
0c678d9
Compare
Yea, totally forgot about the |
91e7bda
to
24abc17
Compare
I think all of the questions, suggestions and concerns raised so far have been addressed and it should be good to go. Should the unreleased section of the changelog be updated as well? |
Technically, this is breaking and hence should be mentioned. However, the only way a user of this crate could use |
9d9e0b7
to
4021797
Compare
Rebased on the latest master and updated the changelog (there's actually quite a few various public-facing changes, not just the |
Is anyone still planning to review this but hasn't had the time so far? If not, I would like merge this on the weekend as I think it is a definite improvement by simplification and has two approvals already. |
@adamreichold Here comes, as promised 😄
This is the preliminary PR to enable further work on #254.
Although there's some breaking changes in here, it's probably better to do it all in one batch because many of these changes are inter-related. I believe all changes are improvements, in one way or another; and there's also some fixes.
An unsorted list of changes:
Element::DATA_TYPE
withElement::IS_POD
Element::same_type()
PyArray_EquivTypes
.PyArray_NewFromDescr
instead ofPyArray_New
to create arrays.FromPyObject::extract()
- it currently doesn't check the instance type and only verifies that dtype is 'O' which may and will lead to unsafe behaviour and so it has to be fixed.ShapeError
intoDimensionalityError
andTypeError
. The latter is no longer typenum-based either and would work with any dtypes; formatting is left for numpy to handle.PyArrayDescr
:into_dtype_ptr()
- an alternative toas_dtype_ptr()
that increfs it; useful since numpy API often steals descriptor referencesof<T>()
- an equivalent topybind11::dtype::of<T>()
is_equiv_to()
- to check if descriptor types are equivalent (PyArray_EquivTypes
)get_typenum()
is made public sinceDataType::from_typenum()
is public; doesn't make much sense to hide itobject()
- a shortcut for creating 'O' dtype (useful in user implementations ofElement
)get_typenum()
toDataType
DataType::Uint64
could be previously mapped tonp.c_ulonglong
instead ofnp.uint64
which is not the same thing. Now,u64
always maps tonp.uint64
.Element
forisize
Open question: one thing that I find extremely confusing is that
DataType::Complex32
maps tonp.complex64
(andComplex64
maps tonp.complex128
). Wouldn't it make more sense if they were named consistently? (i.e. same as in numpy, 64/128)(if this is accepted, I can also work on updating the changelog if needed so.)